[ SOLVED ] QML : how to pass javascript function as argument in another function

您所在的位置:网站首页 qml debuging is enabled [ SOLVED ] QML : how to pass javascript function as argument in another function

[ SOLVED ] QML : how to pass javascript function as argument in another function

2023-11-28 10:08| 来源: 网络整理| 查看: 265

I've check your code and all works on my Mac OS 10.10 with Qt 5.4. The code which I used: @ import QtQuick 2.4 import QtQuick.Controls 1.3 import QtQuick.Window 2.2 import QtQuick.Dialogs 1.2 import "GameHelperJS.js" as GameJS

ApplicationWindow { title: qsTr("Hello World") width: 640 height: 480 visible: true

menuBar: MenuBar { Menu { title: qsTr("&File") MenuItem { text: qsTr("&Open") onTriggered: { dialog1.show(); } } MenuItem { text: qsTr("E&xit") onTriggered: Qt.quit(); } } } Item{ id: self; function refresh(){ GameJS.innerTraversal(self,GameJS.applyRefresh); } function reset(){ GameJS.innerTraversalWithReset(self,GameJS.applyReset); } } Timer { id: timer running: true repeat: true interval: 1000 property bool flag: false onTriggered: { if(flag === false) { flag = true; self.refresh(); } else { flag = false; self.reset(); } } }

} @

I've use timer to call function with period. In console log I've got this: @ Starting /Volumes/Documents/MyWork/PROJECTS/QtProjects/Local/build-sddd-Desktop_Qt_5_4_0_clang_64bit-Debug/sddd.app/Contents/MacOS/sddd... QML debugging is enabled. Only use this in a safe environment. qml: function qrc:/main.qml:83: TypeError: Property 'innerTraversalWithReset' of object [object Object] is not a function qml: function qrc:/main.qml:83: TypeError: Property 'innerTraversalWithReset' of object [object Object] is not a function qml: function qrc:/main.qml:83: TypeError: Property 'innerTraversalWithReset' of object [object Object] is not a function qml: function qrc:/main.qml:83: TypeError: Property 'innerTraversalWithReset' of object [object Object] is not a function qml: function qrc:/main.qml:83: TypeError: Property 'innerTraversalWithReset' of object [object Object] is not a function qml: function qrc:/main.qml:83: TypeError: Property 'innerTraversalWithReset' of object [object Object] is not a function @

As you can see first function (with name innerTraversal) is fire correct and you could see the log message like 'function'.

Also I've checked this code on my virtual machine with Windows 7 and all works fine.

P.S. The second function is not define in your JS.



【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3